package com.iursp.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.multipart.MultipartFile;

import com.iursp.thirdlib.AuthThirdlibHolder;

import groovy.util.logging.Slf4j;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @ClassName: TaskController
 * @Description: 统一对外公共的接口 调用不同bean(需要注册)
 * @author: ruiwu
 * @date: 2018年7月3日 下午6:36:13
 *
 */
@RestController
@RequestMapping(value = "/demo")
@Slf4j
public class AuthThirdlibController extends BaseController {

	@Autowired
	private AuthThirdlibHolder authThirdlibHolder;

	@ApiOperation(value = "对外公共访问接口", notes = "/{path}传入要调用的接口，例：短信---> message ")
	@RequestMapping(value = "/auth/thirdlib/{path}", method = { RequestMethod.GET, RequestMethod.POST })
	public String addUserRoleInfoView(HttpServletRequest request, HttpServletResponse response,
			@PathVariable String path) {
		logger.info("对外公共访问接口，调用" + path);
		try {
			authThirdlibHolder.findThirdlibRole(path).unifiedCall(new ServletWebRequest(request, response));
		} catch (Exception e) {
			e.printStackTrace();
		}
		;
		return null;
	}

	@RequestMapping(value = "/auth/file/multipartUpload", method = RequestMethod.POST)
	public String fileUploadTask(@RequestParam("file") MultipartFile file) {
		logger.info("测试文件上传");
		if (!file.isEmpty()) {
			// 获取文件名
			String fileName = file.getOriginalFilename();
			logger.info("上传的文件名为:" + fileName);
			// 获取文件的后缀名
			String suffixName = fileName.substring(fileName.lastIndexOf("."));
			logger.info("上传的后缀名为:" + suffixName);
			
			
		}
		return "上传成功";
	}

}
